package com.lmaos.basetools.queue3;

import java.lang.reflect.Method;

public class AsyncRunnable implements Runnable{
	AsyncQueue3 asyncQueue3;
	Object obj;
	Method method;
	Object[] params;	
	AsyncResultCallback callback = null;
	String async;
	public AsyncRunnable(AsyncQueue3 asyncQueue3, Object obj, Method method,
			Object[] params,String async) {
		super();
		this.asyncQueue3 = asyncQueue3;
		this.obj = obj;
		this.method = method;
		this.params = params;
		this.async = async;
		callback = asyncQueue3.getAsyncResultCallback(obj.getClass());
	}

	@Override
	public void run() {
		try {
			Object result = this.method.invoke(obj, params);
			if(this.method.getReturnType()!=void.class&&callback!=null){
				callback.onResult(async, result);
			}
		} catch (Exception e) {
			if(callback!=null){
				callback.onError(async, e);
			}
		}
		
	}

}
